<%@page import="java.text.SimpleDateFormat"%>
<%@page import="javax.lang.model.util.SimpleAnnotationValueVisitor6"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@page import="org.nado.member.*, org.nado.bbs.*, java.util.Date, java.util.List"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<%
	request.setCharacterEncoding("UTF-8");
%>
<base href="../resources/" />
<meta http-equiv="content-type" content="text/html; charset= UTF-8" />
<title>nonzero1.0 by nodethirtythree</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link rel="stylesheet" type="text/css" href="style/style.css" />

<style type="text/css">
body{
			background-image: url(img/bg/bg_green.jpg);
	}
.main{
margin-top:18%;
margin-left:35%;
}
table {
	width: 500px;
	border-collapse: collapse;
	text-align: center;
	font-family: 'Trebuchet MS';
}

td,th {
	font-size: 10pt;
	border: 1px solid #ffffff;
	height: 30px;
}

th {
	background-color: #aaaaaa;
	color: #ffffff;
	font-family: Georgia;
}

tr.alt td {
	color: #111111;
	background-color: #dcdcdc;
}
</style>

<script>
function remove() {
	if (confirm('삭제하시겠습니까?')) {
//			alert("${content.bbs_no}");
		location.href = "/web/bbs/remove?bbs_no=${content.bbs_no}&page_no=${page_no}";
	}
}
function modify(){
	location.href = "/web/bbs/modify?bbs_no=${content.bbs_no}&page_no=${page_no}";
}
</script>
</head>

<body>
<div id="header">
</div>

<div id="main">
<div id="main_inner" class="fixed">
<div id="primaryContent_2columns">
<div id="columnA_2columns">
	<H3>Read</H3>
	<p>
	<table>
		<tr>
			<th>글번호</th>
			<th>제목</th>
			<th>작성자</th>
			<th>작성일</th>
			<th>조회수</th>
		</tr>
		<tr>

			<td>${content.bbs_no}</td>
			<td>${content.bbs_title}</td>
			<td>${content.bbs_writer}</td>
			<td><c:set var="date" value="${content.bbs_regDate}" /> 
			<fmt:formatDate	value="${date}" pattern="yyyy/MM/dd" /></td>
			<td>${content.bbs_readcnt}</td>
		</tr>
	</table>
	<table>
		<tr>
			<th>글내용</th>
		</tr>
		<tr>
			<td>${content.bbs_content}</td>
		</tr>
	</table>
	<br>

	<table>
		<tr>
			<%
				BBSBoardVO bbs = (BBSBoardVO) request.getAttribute("content");
				MemberVO login = (MemberVO) session.getAttribute("loginInfo");
				if (login == null || login.equals("")) {
				} else {
					String loginID = login.getMem_id();
					String requestID = bbs.getBbs_writer();
					if (loginID.equals(requestID)) {
			%>
			<td style="text-align: left">
				<input type="button" onclick="remove()" value="삭제하기"></input> 
				<input type="button" onclick="modify()" value="수정하기"></input>
			</td>
			<%
					}
				}
			%>
			<td style="text-align: right">
				<form style='display: inline'
					action="/web/bbs/write?bbs_no=${content.bbs_no}" method="post">
<%-- 					<input type="hidden" name="content" value="${content}"></input> --%>
					<input type="hidden" name="page_no" value="${page_no}"></input>
					<input type="submit" value="답글쓰기"></input>
				</form> 
<!-- 								<a href="javascript:history.back()">  -->
				<a href="/web/bbs/list?page_no=${page_no}"> 
					<input type="button" value="뒤로가기"> </input></a>
			</td>
		</tr>
	</table>

	<button id='showReply'>댓글보기</button><br>
	
	<c:choose>
		<c:when test="${sessionScope['loginInfo']==null}">
				로그인을 해야 댓글 작성이 가능합니다.
		</c:when>
		<c:otherwise>
				<form action="/web/bbs/addReply" method="post">
					<input type="hidden" name="rep_id" value='${loginInfo.mem_id}'>
					<input type="hidden" name="bbs_rep_no" value='${content.bbs_no}'>
					<input type="text" name="rep_content" size="40">
					<input type="submit" value="댓글달기" /><input type="reset" value="다시작성" />
				</form>
		</c:otherwise>
	</c:choose>
	<div id="replys">
	</div>
	<script type="text/javascript"
		src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
	</script>
	<script>
		var bbs_rep_no = ${content.bbs_no};
		$("#showReply").toggle(
		function(){
			console.log("aaa");
			$.getJSON("/web/bbs/getReply/"+bbs_rep_no+".json", function(data){
				
				var str="";
				
				$(data).each(function(idx){
					console.log(this.rep_no);
					console.log(this.rep_content);
					console.log(this.rep_id);
					console.log(this.rep_date);
					str +="<table border = '2' bordercolor = black width= 500px><tr>"
							+"<td width=50px>"+ this.rep_no +"</td>" 
							+"<td width=300px>"+ this.rep_content +"</td> " 
							+"<td width = 50px>"+ this.rep_id +"</td>"
							+"<td width = 50px>"+ this.rep_date+"</td>";
					if(this.rep_id == '${loginInfo.mem_id}'){
					str +="<td width = 50px>"
								+"<form action='/web/bbs/removeReply' method='post'>"
								+"<input type='hidden' name='bbs_rep_no' value='${content.bbs_no}'>"
								+"<input type='hidden' name='rep_no' value="+this.rep_no+">"
								+"<input type='submit' value='삭제하기'></input></form>"+"</td>";
								console.log("삭제 가능");}
					str+="</tr></table>";  
					});
				$("#replys").html(str);
				 $("#showReply").text("댓글 감추기");
			});
			}, function(){
				var str = "";
				 $("#replys").html(str);
				 $("#showReply").text("댓글 보기");
			});
	</script>

	<br> <br> <br>
	<br>
	</p>
	<br> <br class="clear" />
</div>
</div>
</div>
</div>
</body>
</html>